package it.fc.action.users;

import it.fc.action.FcAction;
import it.fc.bean.UserBean;
import it.fc.service.interfaces.IDbService;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;

public class RegisterAction extends FcAction {

	private static final long serialVersionUID = -2425059080002201495L;
	private String nome;
	private String cognome;
	private String email;
	private String sesso;
	private String username;
	private String password;
	private String passwordConfirm;

	private static Logger log = Logger.getLogger(RegisterAction.class);

	@Override
	public String execute() throws Exception {

		log.debug("RegisterAction Execute");
		UserBean user = new UserBean();
		BeanUtils.copyProperties(user, this);
		IDbService dbManager = getDbService();
		
		UserBean fUser = dbManager.findUserByUsername(getUsername());
		
		if(fUser!=null){
		    addActionError(getText("registrazione.err.usernamefind"));
		    return INPUT;
		}
	
		dbManager.insertUser(user); // inserimento utente

		log.debug("Inserimento utente : " + user.getUsername());
 
		//TO DO
		/*MailManager mailManager = new MailManager();
		mailManager.sendHTMLMail("TEst", "<b>ciao</b>", getEmail());
		*/
		return SUCCESS;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getCognome() {
		return cognome;
	}

	public void setCognome(String cognome) {
		this.cognome = cognome;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getSesso() {
		return sesso;
	}

	public void setSesso(String sesso) {
		this.sesso = sesso;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPasswordConfirm() {
		return passwordConfirm;
	}

	public void setPasswordConfirm(String passwordConfirm) {
		this.passwordConfirm = passwordConfirm;
	}

}
